@extends('Layout.main')
@section('content')
    @include('layout.error')
    <div class="col-sm-8 blog-main">
        <form action="/article/{{$article->id}}" method="post" enctype="multipart/form-data">
            {{csrf_field()}}
            {{method_field('put')}}
            <div class="form-group">
                <label>标题</label>
                <input name="title" type="text" class="form-control" placeholder="这里是标题"
                       value="{{ old('title')?old('title'):$article->title}}">
            </div>
            <div class="form-group">
                <label>标题图</label>
                <input type="file" name="pic" class="form-control" id="image">
                <img src="{{old('pic')?old('pic'):$article->thumb_img}}" id="pic" width="100px">
            </div>
            <div class="form-group">
                <label>简介</label>
                <textarea name="intro" class="form-control"
                          placeholder="这里是简介">{{old('intro')?old('intro'):$article->intro}}</textarea>
            </div>
            <div class="form-group">
                <label>内容</label>
                <textarea id="content" name="content"></textarea>
            </div>
            <button type="submit" class="btn btn-default">提交</button>
        </form>
        <br>
    </div><!-- /.blog-main -->
@endsection

@section('my_js')
    <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"></script>
    <script>
        var ue = UE.getEditor('content');
        //对编辑器的操作最好在编辑器ready之后再做
        ue.ready(function () {
            //设置编辑器的内容
            ue.setContent('{{$article->intro}}');
        });
        $('#image').on('change', function () {
            var file = this.files[0];
            $('#pic').attr('src', window.URL.createObjectURL(file));
        })
    </script>
@endsection
